package com.littlepay.kr4.paulin.dfeba77.utils;

import android.graphics.Color;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;

/**
 * Created by 77dfeba on 2017/5/31.
 *
 */

public class SpannableStringUtil {
    public SpannableString  getCostspannableString(String cost){
        cost = new CurrencySymbolUtil().getCurrencySymbol() + cost;
        float total;
        float head;
//        switch (cost.length()){
//            case 12:
//                total = 0.4f;
//                break;
//            case 11:
//                total = 0.45f;
//                break;
//            case 10:
//
//
//
//        }
//        if(cost.length() <= 3){
//            total = 1.0f;
//        }else if (cost.length() <= 5){
//            total = 0.8f;
//        }else if(cost.length() <= 8){
//            total = 0.55f;
//        }else{
//            total = 0.4f;
//        }
        //最大长度是12，自适配字体大小，暂时使用
        //TODO:使用更加完善的字体适配方案
        total = 1.0f - (cost.length() - 3)*0.055f;
        head = total*0.6f;
        SpannableString spannableString = new SpannableString(cost);
        RelativeSizeSpan sizeSpanHead = new RelativeSizeSpan(head);
        RelativeSizeSpan sizeSpanOther = new RelativeSizeSpan(total);
        ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.parseColor("#ff582a"));
        spannableString.setSpan(colorSpan, 0, spannableString.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        spannableString.setSpan(sizeSpanHead, 0, 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        spannableString.setSpan(sizeSpanOther, 1, spannableString.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        return spannableString;
    }
}
